package org.game.cell.config;

import javafx.scene.control.Button;
import lombok.Data;
import org.game.constant.APIConstant;

/**
 * 扫雷单元格
 */
@Data
public class Cell extends Button {
    /**
     * 0 普通的格子
     * 1 被标记的格子
     */
    private boolean flag;

    /**
     * 9 代表雷
     */
    private int mode;

    /**
     * 判断该点是否已经被展示了
     */
    private boolean isShow;

    private int x;
    private int y;

    private final String DEFAULT_COLOR =
            "-fx-background-color: #c7c7c7;" +
            "-fx-border-width: 1;" +
            "-fx-border-color: #fff;";

    private final String FLAG_COLOR =
            "-fx-background-color: #ff0000;" +
                    "-fx-border-width: 1;" +
                    "-fx-border-color: #fff;";

    private final String CLICK_COLOR =
            "-fx-background-color: #ffffff;" +
                    "-fx-border-width: 1;" +
                    "-fx-border-color: #fff;";

    private final String PASSED_COLOR =
            "-fx-background-color: rgba(255,255,255,0);" +
                    "-fx-border-width: 1;" +
                    "-fx-border-color: #fff;";

    private final String MINES_COLOR =
            "-fx-background-color: #ff0065;" +
                    "-fx-border-width: 1;" +
                    "-fx-border-color: #fff;";

    private final String HEADER_COLOR =
            "-fx-background-color: #fc679b;" +
                    "-fx-border-width: 1;" +
                    "-fx-border-color: #fff;";

    private final String BODY_COLOR =
            "-fx-background-color: #ffd4dd;" +
                    "-fx-border-width: 1;" +
                    "-fx-border-color: #fff;";

    private final String FOOD_COLOR =
            "-fx-background-color: #5afd6e;" +
                    "-fx-border-width: 1;" +
                    "-fx-border-color: #fff;";

    public Cell(int mode, int x, int y) {
        this.mode = mode;
        this.flag = false;
        this.x = x;
        this.y = y;
        this.isShow = false;

        setPrefWidth((Integer) APIConstant.CONFIG.get("cellWidth"));
        setPrefHeight((Integer) APIConstant.CONFIG.get("cellHeight"));
        showDefaultColor();
    }

    public void showMode() {
        this.isShow = true;
        setText(String.valueOf(mode));
        showClickColor();
    }

    public void showDefaultColor() {
        if (isShow) {
            return;
        }

        setStyle(DEFAULT_COLOR);
    }

    public void showFlagColor() {
        if (isShow) {
            return;
        }

        setStyle(FLAG_COLOR);
    }

    public void showClickColor() {
        setStyle(CLICK_COLOR);
    }

    public void showPassedColor() {
        setStyle(PASSED_COLOR);
    }

    public void showPassedOrReleasedColor(boolean mode) {
        if (flag || isShow) {
            return;
        }

        if (mode) {
            showPassedColor();
            return;
        }

        if (isShow) {
            showClickColor();
            return;
        }

        showDefaultColor();
    }

    public void showMinesColor() {
        setStyle(MINES_COLOR);
    }

    public void showHeaderColor() {
        setStyle(HEADER_COLOR);
    }

    public void showFoodColor() {
        setStyle(FOOD_COLOR);
    }

    public void showBodyColor() {
        setStyle(BODY_COLOR);
    }
}
